<template>
    <el-header>
        <div class="left" @click="handleCollapsed">
            <el-icon><Menu /></el-icon>
            <span style="margin-left: 10px;">物业收费管理系统</span>
        </div>
        <div class="right">
            <span >欢迎{{store.state.userInfo.username}}回来</span>
            <el-dropdown>
                <span class="el-dropdown-link">
                    <el-icon :size="30"><User/></el-icon>
                    <el-icon class="el-icon--right">
                        <arrow-down />
                    </el-icon>
                </span>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
                        <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>

                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </el-header>
</template>

<script setup>
    import {Menu,User} from "@element-plus/icons-vue";
    import { useStore } from 'vuex'
    import {useRouter} from "vue-router"
    const store = useStore()
    const router = useRouter()
    const handleCollapsed = ()=>{
        store.commit("changeCollapsed")
    }
    const handleCenter = ()=>{ //个人中心跳转
        router.push("/center")
    }
    const handleLogout = ()=>{ //退出跳转
        localStorage.removeItem("token")
        store.commit("clearUserInfo")
        router.push("/login")
    }
</script>

<style lang="scss" scoped>
    .el-header{
        background-color: #2d3a4b;
        color:white;
        width:100%;
        height:60px;
        line-height: 60px;
        display: flex;
        justify-content:space-between;

    }
    .left,.right{
        display:flex;
    }
    .left{
        cursor: pointer; //鼠标点击变成小手
        i{
            margin: auto;
        }
    }
    .right{
        .el-dropdown{
            margin: auto;
            color:white;
            padding-left: 10px;
        }
    }
</style>
